//
//  LoginViewController.m
//  carSecretary
//
//  Created by huangliru on 14-9-4.
//  Copyright (c) 2014年 huangliru. All rights reserved.
//

#import "LoginViewController.h"
#import "ForgetViewController.h"
#import "RegisterViewController.h"
#import "MainViewController.h"
@interface LoginViewController ()

@end

@implementation LoginViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
     UIControl *control = [[UIControl alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
    // 设置用户头像
    self.headImage = [[UIImageView alloc]initWithFrame:CGRectMake(89, 41, 143, 137)];
    self.headImage.image = [UIImage imageNamed:@"people.gif"];
    [control addSubview:self.headImage];
    
    UILabel *nameLable = [[UILabel alloc]initWithFrame:CGRectMake(20, 268, 72, 37)];
    nameLable.text = @"用户名：";
    [control addSubview:nameLable];
    UILabel *pswdLable = [[UILabel alloc]initWithFrame:CGRectMake(20, 337, 72, 37)];
    pswdLable.text = @"密    码：";
    [control addSubview:pswdLable];
    
    // 初始化账号输入
    self.userNameText = [[UITextField alloc]initWithFrame:CGRectMake(89, 272, 201, 30)];
    //让字体大小自适应控件的区域
    [self.userNameText setBorderStyle:UITextBorderStyleRoundedRect];
    [self.userNameText  setAdjustsFontSizeToFitWidth:YES];
    self.userNameText.placeholder = @"请输入您的用户名";
    //设置委托对象
    self.userNameText.delegate = self;
    //添加到本视图
    [control addSubview: self.userNameText];
    
    // 初始化密码输入
    self.passwordText = [[UITextField alloc]initWithFrame:CGRectMake(89, 341, 201, 30)];
    //让字体大小自适应控件的区域
    [self.passwordText setBorderStyle:UITextBorderStyleRoundedRect];
    [self.userNameText  setAdjustsFontSizeToFitWidth:YES];
    self.passwordText.placeholder = @"请输入您的密码";
    self.passwordText.tag = 12;
    self.passwordText.secureTextEntry = YES;
    // 设置委托对象
    self.passwordText.delegate = self;
    //添加到本视图
    [control addSubview: self.passwordText];
    
    // 登录按钮属性设置
    self.loginButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.loginButton.frame = CGRectMake(20, 407, 270, 45);
    [self.loginButton setTitle:@"登  录" forState:UIControlStateNormal];
    self.loginButton.tintColor = [UIColor blackColor];
    
    [self.loginButton setBackgroundImage:[UIImage imageNamed:@"213.png"] forState:UIControlStateNormal];
    [self.loginButton addTarget:self action:@selector(loginButtonPress) forControlEvents:UIControlEventTouchUpInside];
    [control addSubview:self.loginButton];
    
    // 注册账号按钮属性设置
    self.registerButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.registerButton.frame = CGRectMake(20, 487, 120, 45);
    [self.registerButton setTitle:@"注册账号" forState:UIControlStateNormal];
    self.registerButton.tintColor = [UIColor blackColor];
    //    [self.registerButton setBackgroundImage:[UIImage imageNamed:@"forgetButton.gif"] forState:UIControlStateNormal];
    [self.registerButton addTarget:self action:@selector(registerButtonPress) forControlEvents:UIControlEventTouchUpInside];
    [control addSubview:self.registerButton];
    
    // 忘记密码按钮属性设置
    self.forgetButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.forgetButton.frame = CGRectMake(170 , 487, 120, 45);
    self.forgetButton.tintColor = [UIColor blackColor];
    [self.forgetButton setTitle:@"忘记密码" forState:UIControlStateNormal];
    //    [self.forgetButton setBackgroundImage:[UIImage imageNamed:@"forgetButton.gif"] forState:UIControlStateNormal];
    [self.forgetButton addTarget:self action:@selector(forgrtPasswordButtonPress) forControlEvents:UIControlEventTouchUpInside];
    [control addSubview:self.forgetButton];
    
    
    [control addTarget:self action:@selector(textFieldShouldReturn:) forControlEvents:UIControlEventTouchDown];
    self.view = control;
}
//实现textfielddelegate方法
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    [UIView  beginAnimations:@"aa" context:nil];
    [UIView setAnimationDuration:0.3];
    if ([textField tag] == 12)
    {
        CGRect frame = self.view.frame;
        frame.origin.y -= 50;
        self.view.frame = frame;
    }
    [UIView commitAnimations];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [UIView beginAnimations:@"aa" context:nil];
    self.view.frame = CGRectMake(0, 0, 320, 560);
    [UIView setAnimationDuration:0.3];
    [UIView commitAnimations];
    
    
    [self.userNameText resignFirstResponder];
    [self.passwordText resignFirstResponder];
    return YES;
}

// 登录方法实现
-(void)loginButtonPress
{
    MainViewController *mainVC = [[MainViewController alloc]init];
    [self presentViewController:mainVC animated:NO completion:nil];
}

// 注册账号方法实现
-(void)registerButtonPress
{
    RegisterViewController *registerVC = [[RegisterViewController alloc]init];
    [self presentViewController:registerVC animated:NO completion:nil];
}
// 忘记密码方法实现
-(void)forgrtPasswordButtonPress
{
    ForgetViewController *forgetVC = [[ForgetViewController alloc]init];
    [self presentViewController:forgetVC animated:NO completion:nil];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
